from tkinter import ttk
from tkinter import messagebox
import subprocess
import requests
from PIL import Image, ImageTk
from io import BytesIO

mainwindow_func = None

class FTlib:
    def __init__(self, plugin_name):
        self.mainwindow = mainwindow_func
        self.enabled = False  # 新增一个属性来表示FTlib是否启用

    def cmd(self, command):
        subprocess.Popen(command, shell=True)

    def open_url(self, url):
        subprocess.Popen('start ' + url, shell=True)

    def ftlib_version(self):
        return "1.0.1"

    def show_message(self, message):
        messagebox.showinfo("FTlib", message)
    def close_mainwindow(self):
        self.mainwindow.quit()  # 关闭主窗口的功能
    


def run(mainwindow, download_tab, tabs, PluginsAPI):
    global mainwindow_func
    mainwindow_func = mainwindow
    FTlibtabs = ttk.Frame(tabs)
    tabs.add(FTlibtabs, text="FTlib")
    ttk.Label(download_tab, text="FTlib 运行库 已注入").pack()

    # 获取并显示文本信息
    response = requests.get("https://v1.hitokoto.cn/?encode=text")
    ttk.Label(FTlibtabs, text=response.text).pack()
    tk = ttk.tkinter.Tk()
    ftapi = FTlib("FTlib")
    ttk.Label(FTlibtabs, text="FTlib 版本：" + ftapi.ftlib_version()).pack()
    

def need():
    return "mainwindow, download_tab, tabs, PluginsAPI"

def description():
    return "FTlib 运行库 版本 1.0.1"

def inject_class():
    return True
